/*
 * Copyright 2013 Glassy Cinema.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hu.glassy.core.model;

import hu.glassy.model.common.SortableAbstractEntity;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Represents a person who can be associated with the movieRoles
 *
 * @author Alexander Molnár <molnar.alexander@sonrisa.hu>
 */
@Entity
@Table(name = "person")
public class Person extends SortableAbstractEntity
{

  // Field length
  public static final int NAME_LENGTH = 128;
  public static final int DISPLAYNAME_LENGTH = 32;
  public static final int SHORT_DESCRIPTION_LENGTH = 1024;
  public static final int LONG_DESCRIPTION_LENGTH = 6 * 1024;
  public static final int BIRTH_PLACE_LENGTH = 256;

  // Required fields
  public static final boolean NAME_REQUIRED = true;
  public static final boolean DISPLAYNAME_REQUIRED = false;
  public static final boolean SHORT_DESCRIPTION_REQUIRED = true;
  public static final boolean LONG_DESCRIPTION_REQUIRED = false;
  public static final boolean BIRTH_DATE_REQUIRED = true;
  public static final boolean BIRTH_PLACE_REQUIRED = true;

  @Column(name = "name", length = NAME_LENGTH, nullable = !NAME_REQUIRED, unique = false)
  private String name;

  @Column(name = "display_name", length = DISPLAYNAME_LENGTH, nullable = !DISPLAYNAME_REQUIRED, unique = false)
  private String displayName;

  @Column(name = "short_description", length = SHORT_DESCRIPTION_LENGTH, nullable = !SHORT_DESCRIPTION_REQUIRED, unique = false)
  private String shortDescription;

  @Column(name = "long_description", length = LONG_DESCRIPTION_LENGTH, nullable = !LONG_DESCRIPTION_REQUIRED, unique = false)
  private String longDescription;

  @Temporal(TemporalType.DATE)
  @Column(name = "birth_date", nullable = !BIRTH_DATE_REQUIRED, unique = false)
  private Date birthDate;

  @Column(name = "birth_place", length = BIRTH_PLACE_LENGTH, nullable = !BIRTH_PLACE_REQUIRED, unique = false)
  private String birthPlace;

  @OneToMany(mappedBy = "person", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
  @OrderColumn(name = "priority")
  private List<MovieRole> movieRoles = new ArrayList<MovieRole>();

  /**
   * @return the name
   */
  public String getName()
  {
    return name;
  }

  /**
   * @param name the name to set
   */
  public void setName(String name)
  {
    this.name = name;
  }

  /**
   * @return the displayName
   */
  public String getDisplayName()
  {
    return displayName;
  }

  /**
   * @param displayName the displayName to set
   */
  public void setDisplayName(String displayName)
  {
    this.displayName = displayName;
  }

  /**
   * @return the shortDescription
   */
  public String getShortDescription()
  {
    return shortDescription;
  }

  /**
   * @param shortDescription the shortDescription to set
   */
  public void setShortDescription(String shortDescription)
  {
    this.shortDescription = shortDescription;
  }

  /**
   * @return the longDescription
   */
  public String getLongDescription()
  {
    return longDescription;
  }

  /**
   * @param longDescription the longDescription to set
   */
  public void setLongDescription(String longDescription)
  {
    this.longDescription = longDescription;
  }

  /**
   * @return the birthDate
   */
  public Date getBirthDate()
  {
    return birthDate;
  }

  /**
   * @param birthDate the birthDate to set
   */
  public void setBirthDate(Date birthDate)
  {
    this.birthDate = birthDate;
  }

  /**
   * @return the birthPlace
   */
  public String getBirthPlace()
  {
    return birthPlace;
  }

  /**
   * @param birthPlace the birthPlace to set
   */
  public void setBirthPlace(String birthPlace)
  {
    this.birthPlace = birthPlace;
  }

  /**
   * @return the movieRoles
   */
  public List<MovieRole> getMovieRoles()
  {
    return movieRoles;
  }

  /**
   * @param movieRoles the movieRoles to set
   */
  public void setMovieRoles(List<MovieRole> movieRoles)
  {
    this.movieRoles = movieRoles;
  }

}
